import java.util.ArrayList;
import java.util.Arrays;

/**
 * @Description: 包装类的测试代码
 * @Author Stark
 * @Date 2022/1/16 16:56
 **/
class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public boolean equals(Object obj){
        // 1.判断obj是否为空
        if (obj == null) {
            return false;
        }
        // 2.判断obj是否就是自己
        if (obj == this) {
            return true;
        }
        // 3.判断obj是否是Student类的对象
        if (!(obj instanceof Student)) {
            return false;
        }
        // 4.obj一定是Student类的对象而且与当前对象不是一个地址
        // 向下转型还原为Student，比较当前对象的属性和传入对象的属性
        Student stu = (Student) obj;
        return this.name.equals(stu.name) && this.age == stu.age;
    }
}

interface IMessage{
    void print();
}

class MessageImpl implements IMessage{

    @Override
    public void print() {
        System.out.println("hello");
    }
}

public class ObjectTest {
    public static void main(String[] args){
        //自定义类型
        Object obj1 = new Student("张三",40);
        //字符串
        Object obj2 = "hello";
        //顺序表
        Object obj3 = new ArrayList<>();
        //数组引用
        int[] data = new int[]{3,2,5,8,4,7,6,9};
        //接口引用
        IMessage msg = new MessageImpl();
        Object obj4 = data;
        Object obj5 = msg;
        int[] ret = (int[])obj4;
        IMessage imsg = (IMessage) obj5;
        System.out.println(Arrays.toString(ret));
        imsg.print();
    }
}

